#include <stdio.h>
#include <stdlib.h>

#define maxn 5000
#define newline printf("\n")

typedef int ElemType;

typedef struct Node{
    ElemType Data;
    Node *Next;
}*List,Node;

List Read();
void Print(List L);
List Reverse(List L);

int main(){

    List L1,L2;
    L1 = Read();
    L2 = Reverse(L1);
    Print(L1);
    Print(L2);
    return 0;
}


List Read(){

    int n;
    scanf("%d",&n);
    int i,temp;
    List newNode = NULL;
    List L = (List)malloc(sizeof(Node));    //投结点
    List p = L;
    if(L!=NULL){
        for(i=0;i<n;i++){
            scanf("%d",&temp);
            newNode = (List)malloc(sizeof(struct Node));
            newNode->Data = temp;
            p->Next = newNode;
            p = p->Next;
        }
        p->Next = NULL;
    }
    return L->Next;    //根据题意推测返回的是不带头结点的单链表

}


void Print(List L){
    List p = L;
    while(p){
        printf("%d",p->Data);
        p = p->Next;
        if(p!=NULL){
            printf(" ");
        }else{
            printf("\n");
        }
    }

}


List Reverse(List L){

    if(L == NULL||L->Next == NULL){
        return L;
    }
    List head = Reverse(L->Next);
    L->Next->Next = L;        //原来的最后一个结点拼接到新链表的最后一个结点后
    L->Next = NULL;

    return head;
}